package mvc.servlet;

import java.io.File;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;


import mvc.core.XmlParseUtil;
import mvc.model.ActionBean;

public class IniterListener implements ServletContextListener{
	
	private static final String defaultUrl = "actionInXml";

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		
		
	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		ServletContext servletContext = arg0.getServletContext();
		String xmlFile = servletContext.getInitParameter("mvcConfig");
		String realPath = servletContext.getRealPath("/");
		File file = new File(realPath + xmlFile);
		Map<String, ActionBean> map = XmlParseUtil.parseXml(file);
		servletContext.setAttribute(defaultUrl, map);
	}

}
